package it.basilikos.core.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import com.google.common.collect.Lists;

@Entity
@PersistenceContext
@Table(name="conferment")
public class Conferment extends BaseEntity {
	
	private static final long serialVersionUID = 1307913425184775419L;
	
	@Column
	private Date date; 
	
//	@OneToMany(fetch = FetchType.LAZY,cascade={CascadeType.ALL})
	
	@OneToOne
	@NotNull
	private Agent agent;
	
	@OneToMany(mappedBy="conferment",fetch=FetchType.LAZY)
	private List<ProductConferred> products_conferred;
	
	public Conferment(Agent agent){
		date = new Date();
		this.agent = agent;
		products_conferred = Lists.newArrayList();
	}
	

	//full constructor
	public Conferment(Date date, Agent agent,
			List<ProductConferred> products_conferred) {
		super();
		this.date = date;
		this.agent = agent;
		this.products_conferred = products_conferred;
	}



	public Conferment(){}

	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	
	public Agent getAgent() {
		return agent;
	}
	
	
	public void setAgent(Agent agent) {
		this.agent = agent;
	}
	
	public void setProducts_conferred(List<ProductConferred> products_conferred) {
		this.products_conferred = products_conferred;
	}


	@Override
	public String toString() {
		return "Conferment [date=" + date + ", agent=" + agent
				+ ", products_conferred=" + products_conferred + "]";
	}

	
	
}
